package com.woniuxy.store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.store.infra.mapper.PackageMapper;
import com.woniuxy.store.infra.model.Package;
import com.woniuxy.store.service.PackageService;
import exception.MallException;
import org.springframework.stereotype.Service;
import result.CommonResultCodeEnum;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zz
 * @since 2023-07-20
 */
@Service
public class PackageServiceImpl extends ServiceImpl<PackageMapper, Package> implements PackageService {

    @Override
    public void addPackage(Package bean) {
        QueryWrapper<Package> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pay_years",bean.getPayYears());
        Package one = getOne(queryWrapper);
        if (one!=null){
            throw new MallException("改套餐已存在",CommonResultCodeEnum.INVALID_PARAM);
        }
        save(bean);
    }
}
